package com.lingyun.generator.bean;

import com.alibaba.druid.util.StringUtils;
import com.lingyun.generator.utils.NameUtil;

/**
 * Created by bain.wang on 2016/1/11.
 */
public class ColumnInfo {
    private String field; // COLUMN_NAME
    private String type; // DATA_TYPE
    private String nullSet; // IS_NULLABLE
    private String keySet; // COLUMN_KEY
    private String defaultSet; // COLUMN_DEFAULT
    private String extra; // EXTRA
    private String comment;// COLUMN_COMMENT




    // =============================================================================

    /**
     * 获取类似：“CreateTime” 这样的字符串 用来拼 getter/setter 方法
     *
     * @return
     */
    public String getBigJavaName() {
        return NameUtil.getBigJavaName(field);
    }

    /**
     * 获取类似：“createTime” 这样的字符串  用来搞定java变量名称
     *
     * @return
     */
    public String getJavaName() {
        return NameUtil.getJavaName(field);
    }

    /**
     * 字段是否可以为空值
     *
     * @return
     */
    public boolean getNullable() {
        return StringUtils.equals(nullSet, "NO");
    }

    /**
     * 字段对应的java类型
     *
     * @return
     */
    public String getJavaType() {
        if (type.indexOf("bigint") > -1) {
            return "java.lang.Long";
        }

        if (type.indexOf("datetime") > -1
                || type.indexOf("date") > -1
                || type.indexOf("timestamp") > -1
                || type.indexOf("time") > -1) {
            return "java.util.Date";
        }


        if (type.indexOf("int(") > -1) {
            return "java.lang.Integer";
        }

        if (type.indexOf("double") > -1) {
            return "java.lang.Double";
        }

        if (type.indexOf("float") > -1) {
            return "java.lang.Float";
        }


        return "java.lang.String";
    }


    // =============================================================================


    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public String getNullSet() {
        return nullSet;
    }

    public void setNullSet(String nullSet) {
        this.nullSet = nullSet;
    }

    public String getKeySet() {
        return keySet;
    }

    public void setKeySet(String keySet) {
        this.keySet = keySet;
    }

    public String getDefaultSet() {
        return defaultSet;
    }

    public void setDefaultSet(String defaultSet) {
        this.defaultSet = defaultSet;
    }

    public String getExtra() {
        return extra;
    }

    public void setExtra(String extra) {
        this.extra = extra;
    }

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}
